home *** CD-ROM | disk | FTP | other *** search
/ Satanic Rites 4 / Satanic Rites - Issue 4 (1993-05-29)(Destiny).adf / 680x0_Interrupts < prev    next >
Text File  |  1990-01-05  |  5KB  |  132 lines

  1. }0a000
  2.               {g  -============================================-
  3.                {g -=                                          =-
  4.                 {g-= {fInterrupt Handling for Faster Processors {g=-
  5.                 {g-=                                          =-
  6.                 {g-=   {f               by              {g        =-
  7.                 {g-=                                          =-
  8.                 {g-=     {f      Terminator / Destiny {g          =-
  9.                 {g-=                                          =-
  10.                 {g-============================================-
  11.  
  12. {a
  13.    This  article  will  show  you  the  correct way to set up interrupts on all
  14.  versions of the 680x0 processor.
  15.  
  16.    A major incompatablity problem on 68010 + processors is the way in which you
  17.  set the interrupt vectors.
  18.  
  19.    Most  demo  programmers  use  the  following  line  to  set  up  the level 3
  20.  interrupt.
  21.  
  22.   {f      Move.l  #MyLev3,$6c.w{a
  23.  
  24.    Well, this will work fine on the {cMC68000{a.
  25.  
  26.  {a  But on every processor higher than the {e68010{a, the first $100 bytes of memory
  27.  can be anywhere!
  28.  
  29.    This  is  due  to the existance of something called the V.B.R.  Which stands
  30.  for Vector Base Register.
  31.  
  32.    Commodore  wanted to fix the vector table into fastram when they first wrote
  33.  {eWorkbench  2.0 {abut due to the immense incompatablity due to everyone accessing
  34.  the interrupt vectors directly, they couldn't.
  35.  
  36.    The  following routine will allow you to access the interrupt vectors easily
  37.  Modify it to suit your own needs.
  38.  
  39.   {cNOTE! {a  This apply's for any read/write operation between 4.w and $100.w The
  40.  only fixed address is 4.w (Execbase)
  41.  
  42.  
  43. {a;{g----------------------------------------------------------------------------
  44. {a;{g-----{f              Software interrupt handling routines                {g-----
  45. {a;{g----------------------------------------------------------------------------
  46.  
  47.  {a;{e This one should now work on other processors.
  48.  {a;{e Because with the 68010 + you can specify where the vector base table is
  49.  {a;{e in memory and if its been moved and we access $6c.w .... BOOM @!
  50.  {a;{e So we have to use offset $6c from the vector base register.
  51.  {a;{e But first, we have to figure out what processor we're running on...
  52.  {a;{e Take the attnflags from exec. There are several bits,
  53.  {a;{e each stands for a certain processor.
  54.  {a;{e
  55.  {a;{e bit 0 - 68010
  56.  {a;{e bit 1 - 68020
  57.  {a;{e bit 2 - 68030  only OS2
  58.  {a;{e bit 3 - 68040  only OS2
  59.  {a;{e bit 4 - 68881
  60.  {a;{e bit 5 - 68882  only OS2
  61.  {a;{e
  62.  {a;{e note that on a 68020 the 68010 bit is set too etc.
  63.  
  64. {f Setupinterrupts  move.l  4.w,a6          {a;{e execbase
  65.   {f                moveq.l #0,d0           {a;{e Clear reg
  66.     {f              move.w  $128(a6),d0     {a;{e Attnflags from execbase
  67.       {f            and.w   #$f,d0          {a;{e Anything else than 68000 ??
  68.         {f          beq.s   .its68000       {a;{e No. Normal 68000 processor
  69.           {f        move.l  a5,-(a7)        {a;{e Save a5
  70. {f                  lea     getvbr(pc),a5   {a;{e point to Supervisor code
  71.   {f                jsr     -30(a6)         {a;{e Supervisor mode
  72.     {f              move.l  (a7)+,a5        {a;{e Restore a5
  73.        {f           move.l  d0,currentvbr   {a;{e updated vector base
  74. {f .its68000
  75.  
  76. {c ; Now I know where the vector table is so we use an offset
  77.  ; from the base to get the address we wanna change
  78.  
  79.   {f               move.l  currentvbr(pc),a0
  80.     {f             move.l  $6c(a0),OldLev3
  81.       {f           Lea     MyLev3(PC),a1   {a;{e Point to my level 3 interrupt
  82.         {f         Move.l  a1,$6c(a0)      {a;{e Set New Level 3 interrupt
  83.           {f       Rts
  84.  
  85.  {a;{e this piece of code gets the VBR (if available).
  86.  {a;{e this is necessary for accessing $0-$200.
  87.  {a;{e on a 68010 or higher the interrupt table can be placed
  88.  {a;{e anywhere.
  89.  
  90. {f getvbr          dc.l    $4e7a0801
  91.  
  92.  {a;{e The previous longword is the 680x0 instruction  movec vbr,d0
  93.  {a;{e Most assemblers don't understand it
  94.  
  95.   {f               rte
  96.  
  97. {f currentvbr      dc.l    0
  98.  
  99. {f Restoreinterrupts
  100.   {f               move.l  currentvbr(pc),a0
  101.     {f             Move.l  Oldlev3(PC),$6c(a0)     {a;{e Reset Level 3 interrupt
  102.       {f           Rts
  103.  
  104.  
  105. {a  Another thing which isn't really well known is that you can only use certain
  106. exec functions In an interrupt handler.
  107.  
  108. {a  The following exec functions can be safely performed during interrupts:
  109.  
  110. {f Alert
  111.  Disable
  112.  Cause
  113.  Enable
  114.  Findname
  115.  Findport
  116.  Findtask
  117.  Putmsg
  118.  Replymsg
  119.  Signal
  120.  
  121. {a  In  addition,  if  you  are  manipulating  your  own  list structures during
  122. interrupt code, you can also use the following functions:
  123.  
  124. {f Addhead
  125.  Adtail
  126.  Enqueue
  127.  Remhead
  128.  Remtail
  129.  
  130.   {aOkay, that should help you a little bit!
  131.        My thanks must go to {gGeorg Hoermann {afor help with the VBR code.
  132.